package ch10
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;

	import utils.Ball;

	public class Rotate1 extends Sprite
	{
		private var ball:Ball;
		private var vr:Number=.05;
		private var centerX:Number;
		private var centerY:Number;

		public function Rotate1()
		{
			init();
		}

		private function init():void
		{
			ball=new Ball();
			addChild(ball);
			centerX=stage.stageWidth / 2;
			centerY=stage.stageHeight / 2;
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}

		private function onEnterFrame(event:Event):void
		{
			/**
			 * 如果我们只知道物体与中心点的位置又该怎么办呢？
			 * 用 x,y 坐标计算出当前的角度(angle)与半径(radius)也并非难事。
			 * */
			var dx:Number=ball.x - centerX;
			var dy:Number=ball.y - centerY;
			var angle:Number=Math.atan2(dy, dx);
			var radius:Number=Math.sqrt(dx * dx + dy * dy);
			angle+=vr;
			ball.x=centerX + Math.cos(angle) * radius;
			ball.y=centerY + Math.sin(angle) * radius;

		}
	}
}